﻿/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: FZH
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;
using FriendStar.Code;
using FriendStar.Domain.Entity.WareHouse;
using FriendStar.Domain.IRepository.WareHouse;
using FriendStar.Repository.WareHouse;

namespace FriendStar.Application.WareHouse
{
    /// <summary>
	/// 数据表 CLK_42_MX_MaterialProListAcco 对应的数据应用功能类。
	/// </summary>
	public class CLK_42_MX_MaterialProListAccoApp
    {       
        private string UseUnit = Configs.GetValue("UseUnit");  

        private ICLK_42_MX_MaterialProListAccoRepository service = new CLK_42_MX_MaterialProListAccoRepository();

        public List<CLK_42_MX_MaterialProListAccoEntity> GetList(string FDocuNO, string MaterialNO, string MaterialCode, string MaterialSizes, string StandardNumber, string MaterialDemand)
        {
            var expression = ExtLinq.True<CLK_42_MX_MaterialProListAccoEntity>();
            expression = expression.And(t => t.UseUnit == UseUnit);
            expression = expression.And(t => t.FDocuNO == FDocuNO);
            expression = expression.And(t => t.MaterialNO == MaterialNO);
            expression = expression.And(t => t.MaterialCode == MaterialCode);
            expression = expression.And(t => t.MaterialSizes == MaterialSizes);
            expression = expression.And(t => t.StandardNumber == StandardNumber);
            expression = expression.And(t => t.MaterialDemand == MaterialDemand);
            return service.FindList(expression);
        }

        public List<CLK_42_MX_MaterialProListAccoEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<CLK_42_MX_MaterialProListAccoEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.FDocuListID == keyword);
            }
            return service.FindList(expression, pagination);
        }
        
        public CLK_42_MX_MaterialProListAccoEntity GetForm(string keyValue)
        {
            return service.FindEntity(t => t.FDocuListID == keyValue);
        }

        public void DeleteForm(string keyValue)
        {
            service.Delete(t => t.FDocuListID == keyValue);
        }

        public void SubmitForm(CLK_42_MX_MaterialProListAccoEntity entity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                entity.FUpdateBy = OperatorProvider.Provider.GetCurrent().UserName;
                entity.FUpdateDate = DateTime.Now.ToString("yyyy-MM-dd");
                entity.FUpdateTime = DateTime.Now.ToString("HH:mm:ss");
                service.Update(entity);
            }
            else
            {
                entity.FDocuListID = Common.GuId();
                entity.UseUnit = UseUnit;
                entity.FCreateBy = OperatorProvider.Provider.GetCurrent().UserName;
                entity.FCreateDate = DateTime.Now.ToString("yyyy-MM-dd");
                entity.FCreateTime = DateTime.Now.ToString("HH:mm:ss");
                entity.FUpdateBy = OperatorProvider.Provider.GetCurrent().UserName;
                entity.FUpdateDate = DateTime.Now.ToString("yyyy-MM-dd");
                entity.FUpdateTime = DateTime.Now.ToString("HH:mm:ss");
                service.Insert(entity);
            }
        }
    }
}